/*
* Copyright (c) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: Camerality application appui implementation.
*
*/

// INCLUDE FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <f32file.h>
#include <s32file.h>
#include <hlplch.h>
#include <eikbtgpc.h> 

#include <camerality_0xE09A8500.rsg>

#include "camerality.hrh"
#include "cameralitytraces.h"
#include "cameralityapplication.h"
#include "cameralityappui.h"
#include "cameralitycontainer.h"

// ============================ MEMBER FUNCTIONS ===============================

/*!
* CCameralityAppUi::ConstructL()
* Symbian 2nd phase constructor.
*/
void CCameralityAppUi::ConstructL()
    {
    // Initialise app UI with standard value.
    BaseConstructL(EAknEnableSkin|EAppOrientationLandscape);
    iAppView = CCameralityContainer::NewL();
    iAppView->Show(ClientRect());
    
    // Remove status pane
    if (StatusPane()->CurrentLayoutResId() != R_AVKON_STATUS_PANE_LAYOUT_EMPTY)
        {
        StatusPane()->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_EMPTY);
        }    
    }

/*!
* CCameralityAppUi::CCameralityAppUi()
* C++ default constructor.
*/
CCameralityAppUi::CCameralityAppUi()
    : iAppView(NULL)
    {
    // No implementation required
    }

/*!
* CCameralityAppUi::~CCameralityAppUi()
* C++ destructor.
*/
CCameralityAppUi::~CCameralityAppUi()
    {
    if (iAppView)
        {
        RemoveFromStack(iAppView);
        delete iAppView;
        iAppView = NULL;
        }
    }

/**
 * From CAknAppUi
 * Handle window server event.
 */
void CCameralityAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination)
    {
    CAknAppUi::HandleWsEventL(aEvent, aDestination);
    switch (aEvent.Type())
        {
        // Our application has gained focus.
        // Show the main container.
        case EEventFocusGained:
            TRACE("[Camerality] Focus gained event");
            if (iAppView)
                {
                iAppView->Show(ClientRect());
                }
            break;
        // Other application is in foreground hiding our
        // window atleast partially. Release resources
        // for other applications to use.
        case EEventFocusLost:
            TRACE("[Camerality] Focus lost event");
            if (iAppView)
                {
                iAppView->StopAllActivity();
                SetStartSoftkeysL();
                }
            break;            
        default:
            break;
        }
    }

/**
 * From CEikAppUi, HandleCommandL.
 * Takes care of command handling.
 * @param aCommand Command to be handled.
 */
void CCameralityAppUi::HandleCommandL(TInt aCommand)
    {
    switch (aCommand)
        {
        case EEikCmdExit:
        case EAknSoftkeyExit:
            Exit();
            break;                
        case ECommandStart:
            {
            if (iAppView)
                {
                iAppView->StartAllActivityL();                
                SetStopSoftkeysL();
                }
            }
            break;    
        case ECommandStop:
            {
            if (iAppView)
                {
                iAppView->StopAllActivity();
                SetStartSoftkeysL();
                }
            }
            break;                   
        default:
            _LIT(applicationName, "camerality");
            User::Panic(applicationName, 0);            
            break;
        }
    }

/**
 *  HandleStatusPaneSizeChange.
 *  Called by the framework when the application status pane
 *  size is changed.
 */
void CCameralityAppUi::HandleStatusPaneSizeChange()
    {
    if (iAppView)
        {
        iAppView->SetRect(ClientRect());
        }
    }
/**
 * CCameralityAppUi::setStartSoftkeysL
 * Changes the softkeys to Start-Exit
 */
void CCameralityAppUi::SetStartSoftkeysL()
    {
    Cba()->SetCommandSetL(R_SOFTKEYS_START_EXIT);
    Cba()->DrawDeferred();
    }

/**
 * CCameralityAppUi::setStopSoftkeysL
 * Changes the softkeys to Stop-Exit
 */
void CCameralityAppUi::SetStopSoftkeysL()
    {
    Cba()->SetCommandSetL(R_SOFTKEYS_STOP_EXIT);
    Cba()->DrawDeferred();
    }

// End of File
